using System;
using System.Collections.Generic;
using NobleTech.Products.CreatureKingdom.Utils;

namespace NobleTech.Products.CreatureKingdom
{
    public class Move
    {
        public double? DirectionFacing;

        public OrganismInfo.Note HighNote,
            LowNote;

        public double? DirectionMoving;
        public double Speed;

        public struct Interaction
        {
            public enum Types { Attacking, Loving, Eating, Defending, Holding }
            public Types Type;
            public Guid Target;

            public Interaction(Types type, Guid target)
            {
                this.Type = type;
                this.Target = target;
            }
        }
        private List<Interaction> interactions;
        public IEnumerable<Interaction> Interactions { get { return interactions; } }

        public Move()
        {
            DirectionFacing = null;
            HighNote = OrganismInfo.Note.None;
            LowNote = OrganismInfo.Note.None;
            StopMoving();
            interactions = new List<Interaction>();
        }

        public void Clear()
        {
            StopMoving();
            StopInteracting();
        }

        public void Sing(OrganismInfo.Note HighNote, OrganismInfo.Note LowNote)
        {
            this.LowNote = LowNote;
            this.HighNote = HighNote;
        }

        public void StartMoving(double Angle, double Speed)
        {
            this.DirectionMoving = Angle;
            this.Speed = Speed;
        }

        public void StopMoving()
        {
            DirectionMoving = null;
            Speed = 0;
        }

        /// <summary>
        /// Face the direction of the Organism you are interacting with, or the direction you are moving if you are not interacting
        /// </summary>
        /// <returns></returns>
        public void FaceDefault()
        {
            this.DirectionFacing = null;
        }

        public void StopInteracting()
        {
            interactions.Clear();
        }

        public void AddInteraction(Interaction.Types type, Guid target)
        {
            interactions.Add(new Interaction(type, target));
        }

        public void SetInteraction(Interaction.Types type, Guid target)
        {
            StopInteracting();
            AddInteraction(type, target);
        }
    }
}
